package function;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowBook implements IFunction{
    public void act(BookList bookList){
        System.out.println("借阅书籍:");
        Scanner s = new Scanner(System.in);
        System.out.println("请输入要借阅书籍的名字：");
        String bookName = s.nextLine();
        int currentSize = bookList.getBookNum();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(bookName.equals(book.getBookName())){
                if(book.isState() == false){
                    book.setState(true);
                    System.out.println("借阅成功");
                    return;
                }else{
                    System.out.println("已借出，无法借阅");
                    return;
                }
            }
        }
        System.out.println("没有这本书");
    }
}
